package servlet;

import bean.Class;
import service.ClassService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 7:55 下午 2021/6/6
 */
@WebServlet(name = "ClassMainServlet",urlPatterns = "/classMain")
public class ClassMainServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String s=request.getParameter("page");
        int page=0;
        if(s!=null){
            page=(Integer.parseInt(request.getParameter("page")));
        }
        ClassService classService=new ClassService();
        List<Class> allClass = classService.getAllClass(page);
        request.getSession().setAttribute("allClass",allClass);
        //使用转发的机制，转发到classMain.jsp，url不改变，为"/classMain?page=?"的形式
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("classMain.jsp");
        requestDispatcher.forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
